package com.adpython.auth;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.adpython.utils.StrUtil;
import com.google.appengine.repackaged.org.apache.commons.logging.Log;
import com.google.appengine.repackaged.org.apache.commons.logging.LogFactory;

public class UserAuth extends HandlerInterceptorAdapter {
	
	protected  Log log = LogFactory.getLog(getClass());
	
	public boolean preHandle(HttpServletRequest req,HttpServletResponse res, Object handler) throws IOException{
		if(this.isLogin(req)){
			return true;
		}else{
			res.sendRedirect("/login.htm?method=login");
			return false;
		}
	}
	
	private boolean isLogin(HttpServletRequest req){
		if(StrUtil.getCookie(req, "nibiru.adpython.auth")!=null)
			return true;
		return false;
	}
	
}
